package com.zlh.config;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

@Configuration
public class RocketmqProducerUtils {

    private static RocketMQTemplate rocketMQTemplate;

    public RocketMQTemplate getRocketMQTemplate() {
        return rocketMQTemplate;
    }

    @Resource
    public void setRocketMQTemplate(RocketMQTemplate rocketMQTemplate) {
        RocketmqProducerUtils.rocketMQTemplate = rocketMQTemplate;
    }

    public static void sendMessage(String val) {
        Message<String> message = MessageBuilder.withPayload(val).build();
//        rocketMQTemplate.getProducer().setUseTLS(true);
        rocketMQTemplate.getProducer().setSendMsgTimeout(5000);
        rocketMQTemplate.send("test-Topic", message);
    }

    public static void sendBatch(String val) {
        Message<String> message = MessageBuilder.withPayload(val).build();
        rocketMQTemplate.send("batch-Topic", message);
    }
}
